package net.aiion.weave.impl.bytecode;

import net.aiion.weave.asm.FieldVisitor;
import net.aiion.weave.spi.bytecode.BytecodeAnnotationVisitor;
import net.aiion.weave.spi.bytecode.BytecodeClassVisitor;
import net.aiion.weave.spi.bytecode.BytecodeFieldVisitor;
import net.aiion.weave.spi.bytecode.BytecodeMethodVisitor;
import net.aiion.weave.spi.bytecode.events.AnnotationStartBytecodeEvent;
import net.aiion.weave.spi.bytecode.events.AttributeBytecodeEvent;
import net.aiion.weave.spi.bytecode.events.FieldEndBytecodeEvent;

public class BytecodeFieldWriterVisitor implements BytecodeFieldVisitor
{
    private final FieldVisitor mFieldVisitor;

    public BytecodeFieldWriterVisitor(final FieldVisitor aFieldVisitor) {
        mFieldVisitor = aFieldVisitor;
    }

    @Override
    public BytecodeClassVisitor asBytecodeClassVisitor() {
        return null;
    }

    @Override
    public BytecodeAnnotationVisitor asBytecodeAnnotationVisitor() {
        return null;
    }

    @Override
    public BytecodeFieldVisitor asBytecodeFieldVisitor() {
        return this;
    }

    @Override
    public BytecodeMethodVisitor asBytecodeMethodVisitor() {
        return null;
    }

    @Override
    public BytecodeAnnotationVisitor visitAnnotationStart(
        final AnnotationStartBytecodeEvent aAnnotationStartBytecodeEvent)
    {
        return new BytecodeAnnotationWriterVisitor(mFieldVisitor.visitAnnotation(
            aAnnotationStartBytecodeEvent.getDescriptor(), aAnnotationStartBytecodeEvent.getVisible()));
    }

    @Override
    public void visitAttribute(final AttributeBytecodeEvent aAttributeBytecodeEvent) {
        mFieldVisitor.visitAttribute(aAttributeBytecodeEvent.getAttribute());
    }

    @Override
    public void visitFieldEnd(final FieldEndBytecodeEvent aFieldEndBytecodeEvent) {
        mFieldVisitor.visitEnd();
    }
}
